<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="./script/rem.js"></script>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    
    <script type="text/javascript" src="./script/aui-slide.js"></script>
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script></head>
    <script type="text/javascript" src="./script/aui-tab.js" ></script>
    <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
</head>
<body>

    <div id="qiaoliao" style="display: none;">
        <style>
            html,body{height:100%;}
        </style>
        <div class="find-information-box-bg">
            <div class="find-information-box">
                <div class="find-information-box-x" onclick="closeQiaoliao();"></div>
                <img src="image/expression.png">
                <dl>
                    <dt></dt>
                    <dd>分享给微信好友，并在微信中打开链接      查看文章内容</dd>
                </dl>
                <div class="find-information-box-btn" onclick="fenxiang();">立即分享到微信</div>
            </div>
        </div>
    </div>

    <!-- 分享模块 -->
    <div class="fenxiang-bg">
        <div class="fenxiang">
            <ul class="fenxiang-t">
                <li onclick="wxQiaoliaoShare();"><img src="image/foot-share-1.png"></li> 
                <li onclick="friendCircleQiaoliaoShare();"><img src="image/foot-share-2.png"></li> 
                <!-- <li><img src="image/foot-share-3.png"></li>  -->
            </ul>
            <div class="fenxiang-d">取消</div>
        </div>
    </div>

    <header class="find-head fixed" style="padding-top:0.4rem;">
        <ul id="sort">
            <li onclick="changeSort('archive')" id="archive"><p>资料馆</p></li>
            <li onclick="changeSort('college')" id="college"><p>商学院</p></li>
        </ul>
    </header>
    <div class="head-d" style="padding-top:0.4rem;"></div>

    <!-- 资料馆 begin -->
    <div id="list">
<!--     <div class="find-information">
        <div class="find-information-t">
            <p>秋冬美白干货 | 黑白皮也能白成光的身体美白</p>
            208-11-08  10：20
        </div>
        <div class="find-information-m">
            <p>上个月去了趟海边，因为每天都是穿的露肩裙子和吊
带，身上晒的好黑，一下子黑了两个色号</p>
            <div class="find-information-m-d">
                <img src="image/find-information-m-d.png">
            </div>
        </div>
        <ul class="find-information-d">
            <li>
                <i class="fa fa-star active"></i>
                <p>收藏</p>
            </li>
            <li>
                <i class="fa fa-download"></i>
                <p>下载图片</p>
            </li>
            <li>
                <i class="fa fa-clone"></i>
                <p>复制文字</p>
            </li>
            <li>
                <i class="fa fa-mail-forward"></i>
                <p>分享</p>
            </li>
        </ul>
    </div> -->

    <!-- 资料馆 end -->

    <!-- 快抖云 begin -->

<!--     <div class="find-school" tapmode onclick="find_details_audio()">
        <img src="image/find-information-m-d.png">
        <dl>
            <dt>秋冬美白干货 | 黑白皮也能白成光的身体美白</dt>
            <dd>2018-11-08  10：20<span>浏览量：56</span></dd>
        </dl>
    </div>
    <div class="find-school">
        <img src="image/find-information-m-d.png">
        <dl>
            <dt>秋冬美白干货 | 黑白皮也能白成光的身体美白</dt>
            <dd>2018-11-08  10：20<span>浏览量：56</span></dd>
        </dl>
    </div>
    <div class="find-school">
        <img src="image/find-information-m-d.png">
        <dl>
            <dt>秋冬美白干货 | 黑白皮也能白成光的身体美白</dt>
            <dd>2018-11-08  10：20<span>浏览量：56</span></dd>
        </dl>
    </div>

    <div class="find-school-add" tapmode onclick="find_details_video()">
        <img src="image/find-school-add.png">
    </div> -->
</div>
<!-- 快抖云 end -->

<div class="body-bg"></div>

</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/index.js"></script>
<script type="text/template" id="template_left">
    {{~it:value:index}}
    <div class="find-information">
        <div class="find-information-t">
            <p>{{=value.title}}</p>
            {{=value.created_at}}
        </div>
        <div class="find-information-m">
            <p>{{=value.content}}</p>
            <!-- 单张图/视频 -->
            {{? value.files.length == 1}}
            <!-- if 类型为图片 -->
            {{? value.type == 1}}
            <div class="find-information-m-d">
                {{~value.files:valuee:indexx}}
                <div class="find-information-m-d-s"></div>
                <img src="{{=valuee}}" onclick="seeThePic('{{=value.files}}',{{=indexx}});">
                {{~}}
            </div>
            {{??}}
            <!-- else 类型为视频 -->
            <div class="find-information-m-d">
                {{~value.files:valuee:indexx}}
                <div class="find-information-m-d-s"></div>
                <img src="{{=valuee}}" onclick="seeTheVideo('{{=value.files}}');">
                {{~}}
            </div>
            {{?}}
            {{??}}
            <!-- 多张图 -->
            <div class="find-information-m-d-1">
                {{~value.files:valuee:indexx}}
                <img src="{{=valuee}}" onclick="seeThePic('{{=value.files}}',{{=indexx}});">
                {{~}}
            </div>
            {{?}}
        </div>
        <ul class="find-information-d">
            {{? value.is_collection}}
            <!-- <li onclick="education_analysis({{=value.id}});"> -->
            <li onclick="collect({{=value.id}});">
                <i class="fa fa-star active" id="is_collection{{=value.id}}"></i>
                <p>收藏</p>
            </li>
            {{??}}
            <li onclick="collect({{=value.id}});">
                <i class="fa fa-star" id="is_collection{{=value.id}}"></i>
                <p>收藏</p>
            </li>
            {{?}}
            {{? value.type == 1}}
            {{? value.files.length}}
            <li onclick="downLoadPic('{{=value.files}}');">
                <i class="fa fa-download"></i>
                <p>下载图片</p>
            </li>
            {{??}}
            <li>
                <i class="fa fa-download"></i>
                <p>下载图片</p>
            </li>
            {{?}}
            {{??}}
            {{? value.files.length}}
            <li onclick="downLoadPic('{{=value.files}}');">
                <i class="fa fa-download"></i>
                <p>下载视频</p>
            </li>
            {{??}}
            <li>
                <i class="fa fa-download"></i>
                <p>下载视频</p>
            </li>
            {{?}}
            {{?}}
            <li onclick="copyContent('{{=value.content}}');">
                <i class="fa fa-clone"></i>
                <p>复制文字</p>
            </li>
            {{? value.type==1}}
            {{? value.files.length}}
            <li onclick="sharePic('{{=value.files}}');">
                <i class="fa fa-mail-forward"></i>
                <p>分享</p>
            </li>
            {{??}}
            <li>
                <i class="fa fa-mail-forward"></i>
                <p>分享</p>
            </li>
            {{?}}
            {{??}}
            {{? value.files.length}}
            <li onclick="shareVideo('{{=value.files}}');">
                <i class="fa fa-mail-forward"></i>
                <p>分享</p>
            </li>
            {{??}}
            <li>
                <i class="fa fa-mail-forward"></i>
                <p>分享</p>
            </li>
            {{?}}
            {{?}}
        </ul>
    </div>
    {{~}}
</script>

<script type="text/template" id="template_right">
    {{~it:value:index}}
    <!-- <div class="find-school" tapmode onclick="find_details_audio()"> -->
    <div class="find-school" tapmode>
        {{? value.category == 1}}
        <img src="{{=value.photo}}" onclick="qiaoliaoShare('{{=value.ext}}','{{=value.id}}');">
        {{??}}
        <img src="{{=value.photo}}" onclick="gotoVideo('{{=value.ext}}','{{=value.id}}');">
        {{?}}
        <div class="find-school-d">
            <dl>
                <dt>{{=value.title}}</dt>
                <dd>{{=value.created_at}}<span>浏览量：{{=value.number_views}}</span></dd>
            </dl>
            <!-- <div class="find-school-btn">一键分享</div> -->
        </div>
    </div>
    {{~}}
<!--     <div class="find-school-add" tapmode onclick="find_details_video();">
        <img src="image/find-school-add.png">
    </div> -->

</script>

<script type="text/javascript">

    apiready = function(){

        var KDY = $api.getStorage('KDY');
        if (KDY == 1) {
            sortName = 'college';
            $('#sort li').addClass('active');
            $('#archive').removeClass('active');
            loadCollege();      
            $api.setStorage('KDY', null);      
        }else{
            sortName = 'archive';
            $('#sort li').removeClass('active');
            $('#archive').addClass('active');
            loadArchive();
        }
        pullLoading();
        pullRefresh();
        reloadListener(); 
    }

    // 加载资料馆数据
    function loadArchive(more){

        // 进度提示框
        api.showProgress({
            title: '努力加载中...',
            text: '请稍等...',
            modal: false
        });

        if (more) {
            page += 1;
        }else{
            page = 1;
        }

        var token = $api.getStorage('token');
        api.ajax({
            url: webAddress + '/api/archive/index',
            method: 'get',
            data: {
                values: {
                    page: page,
                    row: row,
                },
            },
            headers: {
                Authorization: 'Bearer ' + token,
                Accept: 'application/json',
            },
        },function(ret, err){
            if (ret) {
                // alert( JSON.stringify( ret ) );
                api.hideProgress();
                // 关闭下拉刷新控件
                api.refreshHeaderLoadDone();
                data = ret.data;
                if (more) {
                    templateFun(1,ret.data,1);
                }else{
                    templateFun(0,ret.data,1);
                }
            } else {
                // alert( JSON.stringify( err ) );
                api.toast({
                    msg: err.body.message,
                    duration: 2000,
                    location: 'bottom'
                });
                return false;
            }
        });
    }

        // 加载快抖云数据
        function loadCollege(more){

            // 进度提示框
            api.showProgress({
                title: '努力加载中...',
                text: '请稍等...',
                modal: false
            });


            if (more) {
                page += 1;
            }else{
                page = 1;
            }

            var token = $api.getStorage('token');
            api.ajax({
                url: webAddress + '/api/education/index',
                method: 'get',
                data: {
                    values: {
                        page: page,
                        row: row,
                        category: 1,
                    },
                },
                headers: {
                    Authorization: 'Bearer ' + token,
                    Accept: 'application/json',
                },
            },function(ret, err){
                if (ret) {
                    // alert( JSON.stringify( ret ) );
                    api.hideProgress();
                    // 关闭下拉刷新控件
                    api.refreshHeaderLoadDone();
                    if (more) {
                        templateFun(1,ret.data,2);
                    }else{
                        templateFun(0,ret.data,2);
                    }
                } else {
                    // alert( JSON.stringify( err ) );
                    if (err.body.message) {
                        api.toast({
                            msg: err.body.message,
                            duration: 2000,
                            location: 'bottom'
                        });
                        return false;
                    }
                }
            });
        }

    // 模板赋值函数(资料馆)
    function templateFun(more,data,type){
        if (!more && !data.length) {

            // 初次进入页面 无数据
            var list = $api.byId('list');
            var html = '<h2 style="padding:1rem; text-align:center; color:#999; font-size:0.5rem;">暂无内容</h2>';
            list.innerHTML = html;
        }else{


           if (type == 1) {
              var template = $api.byId('template_left');
          }else{


            var template = $api.byId('template_right');
        }
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list');

        if (more) {


            if (data.length) {


                $api.append(list, html);
            }else{


             api.toast({
              msg: '没有更多了',
              duration: 2000,
              location: 'bottom'
          });
             return false; 
         }
     }else{

         $api.html(list, html);
     }

 }
}


    // 跳转网页
    function gotoWeb(webUrl,id){
        education_analysis(id);
        api.openWin({
            name: 'web_view',
            url: './web_view.html',
            pageParam: {
                url: webUrl,
                title: '快抖云',
            }
        });
    }

    // 播放快抖云视频
    function gotoVideo(webUrl,id){
        education_analysis(id);
        api.openVideo({
            url: webUrl
        });
    }

    // 收藏
    function collect(id){
        var token = $api.getStorage('token');
        if (!token) {

            api.confirm({
                title: '提示!',
                msg: '是否登录?',
                buttons: ['确定', '取消']
            }, function(ret, err){
                if( ret ){
                    // alert( JSON.stringify( ret ) );
                    if (ret.buttonIndex == 1) {
                        api.openWin({
                            name: 'login',
                            url: './login.html',
                        });
                    }
                }else{
                    // alert( JSON.stringify( err ) );
                }
            });

        }else{
            api.ajax({
                url: webAddress + '/api/archive/'+id+'/collection',
                method: 'post',
                data: {
                    values: {
                    },
                },
                headers: {
                    Authorization: 'Bearer ' + token,
                    Accept: 'application/json',
                },
            },function(ret, err){
                if (ret) {
                // alert( JSON.stringify( ret ) );
                if (ret.status_code == 200) {
                    api.toast({
                        msg: ret.message,
                        duration: 2000,
                        location: 'bottom'
                    });
                }

                // $('#is_collection').addClass('active');
                $('#is_collection'+id).toggleClass('active');

            } else {
                // alert( JSON.stringify( err ) );
                if (err.statusCode == 400) {
                    api.toast({
                        msg: err.body.message,
                        duration: 2000,
                        location: 'bottom'
                    });
                    return false;
                }
            }
        });
        }
    }

    // 统计
    function education_analysis(id){
        var token = $api.getStorage('token');
        api.ajax({
            url: webAddress + '/api/education/'+id+'/analysis',
            method: 'post',
            data: {
                values: {
                },
            },
            headers: {
                Authorization: 'Bearer ' + token,
                Accept: 'application/json',
            },
        },function(ret, err){
            if (ret) {
                // alert( JSON.stringify( ret ) );
                // if (ret.status_code == 200) {
                //     api.toast({
                //         msg: ret.message,
                //         duration: 2000,
                //         location: 'bottom'
                //     });
                // }

            } else {
                // alert( JSON.stringify( err ) );
                if (err.statusCode == 400) {
                    api.toast({
                        msg: err.body.message,
                        duration: 2000,
                        location: 'bottom'
                    });
                    return false;
                }
            }
        });
    }

    // 预览图片
    function seeThePic(images,index){
        var systemType = api.systemType;
        if (systemType == 'ios') {
            images = images.split(',');
            var photoBrowser = api.require('photoBrowser');

            photoBrowser.open({
                images: images,
                activeIndex: index,
                // placeholderImg: 'widget://res/img/apicloud.png',
                bgColor: '#000'
            }, function(ret, err) {
                if (ret) {
                    // alert(JSON.stringify(ret));
                    if (ret.eventType == 'click') {
                     photoBrowser.close(); 
                 }
             } else {
                    // alert(JSON.stringify(err));
                    photoBrowser.close(); 
                }
            });
        }else{
           api.openWin({
            name: 'preview_pic',
            url: './preview_pic.html',
            pageParam: {
                images: images,
                index: index,
            }
        }); 
       }
   }

    // 观看资料馆视频
    function seeTheVideo(url){
        api.openVideo({
            url: url
        });
    }

    // 下载图片
    function downLoadPic(files){

        // 进度提示框
        api.showProgress({
            title: '下载中...',
            text: '请稍等...',
            modal: false
        });

        files = files.split(',');

        for (var i = files.length - 1; i >= 0; i--) {

            // 下载
            api.download({
                url : files[i],
                // savePath : 'fs://test.png',
                report : true,
                cache : true,
                allowResume : true
            }, function(ret, err) {
                if (ret.state == 1) {
                //下载成功
                api.saveMediaToAlbum({
                    path : ret.savePath
                }, function(ret, err) {
                    if (ret && ret.status) {
                        api.hideProgress();
                        api.toast({
                            msg: '下载成功',
                            duration: 2000,
                            location: 'bottom'
                        });                            
                    } else {
                        api.hideProgress();
                        api.toast({
                            msg: '下载失败',
                            duration: 2000,
                            location: 'bottom'
                        });                            
                    }
                });
            } else {
            }
        });
        }

    }

    // 下载视频
    function downLoadVideo(files){
        files = files.split(',');

        for (var i = files.length - 1; i >= 0; i--) {

            // 下载
            api.download({
                url : files[i],
                // savePath : 'fs://test.png',
                report : true,
                cache : true,
                allowResume : true
            }, function(ret, err) {
                if (ret.state == 1) {
                //下载成功
                api.saveMediaToAlbum({
                    path : ret.savePath
                }, function(ret, err) {
                    if (ret && ret.status) {

                        api.toast({
                            msg: '下载成功',
                            duration: 2000,
                            location: 'bottom'
                        });                            
                    } else {

                        api.toast({
                            msg: '下载失败',
                            duration: 2000,
                            location: 'bottom'
                        });                            
                    }
                });
            } else {
            }
        });
        }
    }

    // 复制文字
    function copyContent(content){

        var clipBoard = api.require('clipBoard');
        clipBoard.set({
            value: content
        }, function(ret, err) {
            if (ret) {
                api.toast({
                    msg: '复制成功',
                    duration: 2000,
                    location: 'bottom'
                });  
                // clipBoard.get(function(ret, err) {
                //     if (ret) {
                //         // alert(JSON.stringify(ret));
                //     } else {
                //         // alert(JSON.stringify(err));
                //     }
                // });
            } else {
                // alert(JSON.stringify(err));
            }
        });

    }

    // 分享图片
    function sharePic(files){

        api.showProgress({
            title: '正在获取图片...',
            text: '请稍候...',
            modal: false
        });

        files = files.split(',');
        imagePaths = [];
        for (var i = 0; i < files.length; i++) {

            // 下载
            api.download({
                url : files[i],
                report : false,
                cache : true,
                allowResume : false
            }, function(ret, err) {
                // alert(JSON.stringify(ret));

                if (ret.state == 1) {
                    //下载成功
                    imagePaths.push(ret.savePath);
                    if (imagePaths.length == files.length) {
                        // 关闭提示
                        api.hideProgress();
                        var sharedModule = api.require('shareAction');
                        sharedModule.share({
                            type: 'image',
                            images: imagePaths,
                            thumbnail: imagePaths,
                        });
                    }
                } else {

                }
            });
        }
    }

    // 分享视频
    function shareVideo(files){
        files = files.split(',');
        var sharedModule = api.require('shareAction');
        sharedModule.share({
            path: files[0],
            type: 'url'
        });
    }

    // 千聊分享弹框
    function qiaoliaoShare(url){
        $('#qiaoliao').css('display', 'block');
        qiaoliaoUrl = url;
    }

    // 分享千聊到微信
    function wxQiaoliaoShare(){

        var wx = api.require('wx');
        wx.shareWebpage({
           apiKey: 'wx7cf56a1ffd5ea7a1',
           scene: 'session',
           title: '一品亿赚',
           description: '新派互联网创业平台',
           thumb: 'widget://wgt/fenxiang.jpg',
           contentUrl: qiaoliaoUrl
       }, function(ret, err){
            //  alert(JSON.stringify(ret));
            if (ret.status){
                api.toast({
                    msg: '分享成功',
                    duration: 2000,
                    location: 'bottom',
                    global: true,
                });

                // api.execScript({name: 'lphd',script: 'closeShare();'});
            }else{
                // alert(err.code);
            }
        });
    }

    // 分享千聊到朋友圈
    function friendCircleQiaoliaoShare(){

        var wx = api.require('wx');
        wx.shareWebpage({
           apiKey: 'wx7cf56a1ffd5ea7a1',
           scene: 'timeline',
           title: '一品亿赚',
           description: '新派互联网创业平台',
           thumb: 'widget://wgt/fenxiang.jpg',
           contentUrl: qiaoliaoUrl
       }, function(ret, err){
            //  alert(JSON.stringify(ret));
            if (ret.status){
                api.toast({
                    msg: '分享成功',
                    duration: 2000,
                    location: 'bottom',
                    global: true,
                });

                // api.execScript({name: 'lphd',script: 'closeShare();'});
            }else{
                // alert(err.code);
            }
        });
    }

    // 关闭千聊弹窗
    function closeQiaoliao(){
        $('#qiaoliao').css('display', 'none');
    }

    // 监听事件 (页面刷新)
    function reloadListener(){
        api.addEventListener({
            name: 'reload',
        }, function(ret, err){
         if (sortName == 'archive') {
            loadArchive();
        }else{
            loadCollege();
        }
    });
    }

    // 切换分类(资料馆/快抖云)
    function changeSort(sort){
        $('#sort li').removeClass('active');
        $('#'+sort).addClass('active');
        if (sort == 'archive') {
            loadArchive();
            sortName = 'archive';
        }else{
            loadCollege();
            sortName = 'college';
        }
    }

    // 上拉加载
    function pullLoading(){
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 0
            }
        }, function(ret, err){
            if (sortName == 'archive') {
                loadArchive(1);
            }else{
                loadCollege(1);
            }
        });
    }

    // 下拉刷新
    function pullRefresh(){
        api.setRefreshHeaderInfo({
            // loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...'
        }, function(ret, err) {
            //在这里从服务器加载数据，加载完成后调用api.refreshHeaderLoadDone()方法恢复组件到默认状态
            if (sortName == 'archive') {
                loadArchive();
            }else{
                loadCollege();
            }
        });
    }

    function find_details_audio() {
        api.openWin({
            name: 'find_details_audio',
            url: './find_details_audio.html',
        });
    }

    // 发布新快抖云
    function find_details_video() {

        // 判断是否登录
        var token = $api.getStorage('token');
        if (!token) {
            api.confirm({
                title: '提示!',
                msg: '是否登录?',
                buttons: ['确定', '取消']
            }, function(ret, err){
                if( ret ){
                    // alert( JSON.stringify( ret ) );
                    if (ret.buttonIndex == 1) {
                        api.openWin({
                            name: 'login',
                            url: './login.html',
                        });

                    }
                }else{
                    // alert( JSON.stringify( err ) );
                }
            });
        }else{
            api.openWin({
                name: 'find_details_video',
                url: './find_details_video.html',
            });
        }
    }

    function index() {
        api.openWin({
            name: 'index',
            url: './index.html',
        });
    }
    function shop() {
        api.openWin({
            name: 'shop',
            url: './shop.html',
        });
    }
    function user_index() {
        api.openWin({
            name: 'user_index',
            url: './user_index.html',
        });
    }
    function closeWin(){
        api.closeWin({
        });
    }
</script>
</html>